package com.goods.controller.business;

import com.goods.business.service.ConsumerService;
import com.goods.business.service.SupplierService;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ConsumerVO;
import com.goods.common.vo.business.SupplierVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 物资来源
 */
@RestController
@RequestMapping("/business/supplier")
public class SupplierController {


    @Autowired
    private SupplierService supplierService;

    //加载系别列表
    //queryMap: { pageNum: 1, pageSize: 10, name: "" }, //查询对象
    @GetMapping("/findSupplierList")
    public ResponseBean<PageVO<SupplierVO>> getSupplierList(@RequestParam("pageNum") Integer pageNum,
                                                            @RequestParam("pageSize") Integer pageSize,
                                                            @RequestParam("name") String name){
      PageVO<SupplierVO> pageVO =  supplierService.getSupplierList(pageNum,pageSize,name);
        return ResponseBean.success(pageVO);
    }

    //添加
    @PostMapping("/add")
    public ResponseBean add(@RequestBody SupplierVO supplierVO){
        supplierService.add(supplierVO);
        return ResponseBean.success();
    }

    //打开弹窗
    @GetMapping("/edit/{id}")
    public ResponseBean<SupplierVO> edit(@PathVariable Long id){
       SupplierVO supplierVO =  supplierService.edit(id);
        return ResponseBean.success(supplierVO);
    }

    //更新
    @PutMapping("/update/{id}")
    public ResponseBean update(@PathVariable Long id,@RequestBody SupplierVO supplierVO){
        supplierService.update(id,supplierVO);
        return ResponseBean.success();
    }

    //删除来源
    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id){
        supplierService.delete(id);
        return ResponseBean.success();
    }

}
